package cn.edu.scau.cmi.chenjiale.composite;

import cn.edu.scau.cmi.chenjiale.composite.clarity.ClarityIndividual;
import cn.edu.scau.cmi.chenjiale.composite.clarity.ClarityOrganization;
import cn.edu.scau.cmi.chenjiale.composite.clarity.ClarityOrganizationComposite;
import cn.edu.scau.cmi.chenjiale.composite.safe.SafeIndividual;
import cn.edu.scau.cmi.chenjiale.composite.safe.SafeOrganization;
import cn.edu.scau.cmi.chenjiale.composite.safe.SafeOrganizationComposite;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * 主启动类
 * 
 * 
 * @author chen
 * @date 2019/04/16
 *
 */
public class CompositeClient extends Application {

	@Override
	public void start(Stage primaryStage) throws Exception {
        BorderPane pane = new BorderPane();
        HBox hbox = new HBox(5);
        TextArea textArea = new TextArea();
        Label safe = new Label("安全形式：");
        Label clarity = new Label("透明形式：");
        
        Button bt1 = new Button("显示个体");
        Button bt2 = new Button("显示组织");
        Button bt3 = new Button("显示个体");
        Button bt4 = new Button("显示组织");
        
        hbox.getChildren().addAll(safe,bt1,bt2,new Label("     "),clarity,bt3,bt4);
        hbox.setAlignment(Pos.CENTER);
        pane.setTop(hbox);
        pane.setCenter(textArea);
        
        Scene scene = new Scene(pane,500,400);
        primaryStage.setScene(scene);
        primaryStage.setTitle("组合模式");
        primaryStage.show();
    
        SafeOrganizationComposite organization1 = new SafeOrganizationComposite("组织1");
        SafeOrganizationComposite organization11 = new SafeOrganizationComposite("组织1-1");
        SafeOrganization individual1 = new SafeIndividual("个体1");
        organization11.addChild(individual1);
        organization1.addChild(organization11);
        
        bt1.setOnAction(e->{
        	textArea.setText(individual1.display());
        });
        
        bt2.setOnAction(e->{
        	textArea.setText(organization1.display());
        });
        
        ClarityOrganizationComposite organization2 = new ClarityOrganizationComposite("组织2");
        ClarityOrganizationComposite organization21 = new ClarityOrganizationComposite("组织2-1");
        ClarityOrganization individual2 = new ClarityIndividual("个体2");
        organization21.addChild(individual2);
        organization2.addChild(organization21);
        
        bt3.setOnAction(e->{
        	textArea.setText(individual2.display());
        });
        
        bt4.setOnAction(e->{
        	textArea.setText(organization2.display());
        });
          
	}

	public static void main(String[] args) {
		Application.launch(args);
	}

}
